/*
 * Copyright 2007 Matt Jensen
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations under the License.
 */
package org.jtell.internal.config.xml;

import java.util.Set;
import java.util.HashSet;

/**
 * <p>
 * <code>HandlerElement</code> accumulates and holds the information in an <code>&lt;handler ...&gt;</code>
 * configuration element.
 * </p>
 * <p>
 * <strong>Thread Safety</strong><br/>
 * Instances of this class are not safe for multithreaded access.
 * </p>
 */
public class HandlerElement
{
    /**
     * <p>
     * The <code>after</code> tokens.
     * </p>
     */
    private final Set<OrderElement> m_afterOrders = new HashSet<OrderElement>();

    /**
     * <p>
     * The <code>before</code> tokens. 
     * </p>
     */
    private final Set<OrderElement> m_beforeOrders = new HashSet<OrderElement>();

    /**
     * <p>
     * The order tokens contributed by this handler.
     * </p>
     */
    private final Set<String> m_contributeTokens = new HashSet<String>();

    /**
     * <p>
     * The nested <code>&lt;handler ...&gt;</code> elements.
     * </p>
     */
    private final Set<EventElement> m_events = new HashSet<EventElement>();

    /**
     * <p>
     * The handler method signature. 
     * </p>
     */
    private String m_methodSignature;

    /**
     * <p>
     * Construct a {@link HandlerElement} instance.
     * </p>
     */
    public HandlerElement()
    {
        super();
    }

    public HandlerElement addAfterOrder(final String token, final boolean required)
    {
        m_afterOrders.add(new OrderElement(token, required));
        return this;
    }

    public HandlerElement addBeforeOrder(final String token, final boolean required)
    {
        m_beforeOrders.add(new OrderElement(token, required));
        return this;
    }

    public HandlerElement addContributeToken(final String token)
    {
        m_contributeTokens.add(token);
        return this;
    }

    public HandlerElement addEvent(final EventElement eventElement)
    {
        m_events.add(eventElement);
        return this;
    }

    public Set<OrderElement> getAfterOrders()
    {
        return m_afterOrders;
    }

    public Set<OrderElement> getBeforeOrders()
    {
        return m_beforeOrders;
    }

    public Set<String> getContributeTokens()
    {
        return m_contributeTokens;
    }

    public Set<EventElement> getEvents()
    {
        return m_events;
    }

    public String getMethodSignature()
    {
        return m_methodSignature;
    }

    public HandlerElement setMethodSignature(String methodSignature)
    {
        m_methodSignature = methodSignature;
        return this;
    }
}
